import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
 * The bloodstream is the setting for our White Blood Cell scenario. 
 * It's a place where blood cells, bacteria and viruses float around.
 * 
 * @author Michael Kölling
 * @version 0.1
 */
public class Bloodstream extends World
{
    private int score=0;
    private int time=2020;
    
    /**
     * Constructor: Set up the starting objects.
     */
    public Bloodstream()
    {    
        super(780, 360, 1); 
        setPaintOrder(Border.class);
        prepare();
        //score=0;
        //time=2020;
        showScore();
        showTime();
        //showText("score:",100,100);
    }
    
    private void showEndMessage()
    {
        showText("Time is up - you win!",400,200);
        showText("You final score:"+score+ "getscore",400,250);
    }
    
    private void showTime()
    {
        showText("Time: "+time,700,25);
    }
    
    private void countTime()
    {
        time--;
        showTime();
        if(time == 0)
        {
           showEndMessage();
           Greenfoot.stop();
        }
    }
    
    private void showScore()
    {
        showText("Score: "+score,100,25);
    }
    
    public void addScore(int getscore)
    {
        score =getscore;
        showScore();
        if(score<0)
        {
           Greenfoot.playSound("game-over.wav");
           Greenfoot.stop();
        }  
    }
    
    /**
     * Create new floating objects at irregular intervals.
     */
    public void act()
    {
        if (Greenfoot.getRandomNumber(100) < 3)
        {
            addObject(new Bacteria(), 779, Greenfoot.getRandomNumber(360));
        }
        
        if (Greenfoot.getRandomNumber(100) < 2)
        {
            addObject(new Redcell(), 779, Greenfoot.getRandomNumber(360));
        }
        
        if (Greenfoot.getRandomNumber(100) < 1)
        {
            addObject(new Virus(), 779, Greenfoot.getRandomNumber(360));
        }
        countTime();
    }
    
    /**
     * Prepare the world for the start of the program. In this case: Create
     * a white blood cell and the lining at the edge of the blood stream.
     */
    private void prepare()
    {
        WhiteCell whitecell = new WhiteCell();
        addObject(whitecell, 83, 179);
        Lining lining = new Lining();
        addObject(lining, 126, 1);
        Lining lining2 = new Lining();
        addObject(lining2, 342, 5);
        Lining lining3 = new Lining();
        addObject(lining3, 589, 2);
        Lining lining4 = new Lining();
        addObject(lining4, 695, 5);
        Lining lining5 = new Lining();
        addObject(lining5, 114, 359);
        Lining lining6 = new Lining();
        addObject(lining6, 295, 353);
        Lining lining7 = new Lining();
        addObject(lining7, 480, 358);
        Lining lining8 = new Lining();
        addObject(lining8, 596, 359);
        Lining lining9 = new Lining();
        addObject(lining9, 740, 354);
        Border Border1 = new Border();
        addObject(new Border(),0,180);
        Border Border2 = new Border();
        addObject(new Border(),780,180);
    }
}
